import axios from "axios";
let isProd = process.env.NODE_ENV === 'production';
let baseURL;

isProd = true;
// isProd = false;
if (isProd) {
    // baseURL = "http://huruqing.cn:3006";
    baseURL = "http://81.71.65.4:3006";

} else {

    baseURL = "http://localhost:3006";
    // baseURL = "http://192.168.2.21:3006";

}
const service = axios.create({
    baseURL,
    timeout: 10 * 60 * 1000,
});

//4. 请求拦截
service.interceptors.request.use(
    (config) => {
        // do something
        config.headers["user-token"] = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImJmY2M3OGQwNWY1OSIsImNyZWF0ZVRpbWUiOjE2Njc5MDc0NTkyOTIsInVwZGF0ZVRpbWUiOjE2Njc5MDc0NTkyOTIsInBob25lIjoiMTU5OTQzMTAxNDciLCJzbXNDb2RlIjo3NzcwLCJpYXQiOjE2Njc5MDc0NjEsImV4cCI6MTY3MTUwNzQ2MX0.4S8rjCi8ZNcTUJMTftUACFACBY3MOpVJrc2xrOVSM2s';
        return config;
    },
    (err) => {
        return Promise.reject(err);
    }
);

service.interceptors.response.use(
    (res) => {
        const data = res.data;
        if (data.code != 666) {
            return Promise.reject(data.msg);
        }
        return data;
    },
    (err) => {
        return Promise.reject(err);
    }
);



export default service